﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace Config
{



    public partial class ConfigForm : Form
    {
       public  string selectpathconfig = "";
       
      
        public ConfigForm(string path)
               
        {
            
            InitializeComponent();
            selectpathconfig = path;
        }


        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Application.StartupPath;//注意里写路径时要用c:\\而c:\
            openFileDialog.Filter = "配置文件|*.*|配置文件|*.dat|所有文件|*.*";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                String path = openFileDialog.FileName;
                if (!File.Exists(path))
                {
                    MessageBox.Show("未选中文件");
                    path = "";
                    return;
                }
                labelPath.Text = "配置文件:<" + path + ">";
                button1.Visible = false;
            }
        }
        
       
        

        public void ReadData(string path)
        {
           StreamReader sr = new StreamReader(path, System.Text.Encoding.Default);
            String line;
            try
            {
                sr.ReadLine();
                line = sr.ReadLine();//out.t76
                this.textBox00.Text = line;
                


                sr.ReadLine();
                line = sr.ReadLine();//是否滤波(1为滤波，0为不滤波):
                if (line.Trim().Equals("0"))
                    this.checkBox1.Checked = false;
                else
                    this.checkBox1.Checked = true;

                sr.ReadLine();
                line = sr.ReadLine();//远参考（0为单站，1为远参考）
                if (line.Trim().Equals("0"))
                    this.checkBox2.Checked = false;
                else
                    this.checkBox2.Checked = true;

                sr.ReadLine();
                line = sr.ReadLine();//远参考站点名
                this.textBox0.Text = line;

                sr.ReadLine();
                line = sr.ReadLine();//是否做磁场相关(0为不做，1为做)
                if (line.Trim().Equals("0"))
                    this.checkBox3.Checked = false;
                else
                    this.checkBox3.Checked = true;

                sr.ReadLine();
                line = sr.ReadLine();//是否做磁场共用(0为不做，1为做)
                if (line.Trim().Equals("0"))
                    this.checkBox5.Checked = false;
                else
                    this.checkBox5.Checked = true;


                List<ConfigData> list = new List<ConfigData>();
                sr.ReadLine();
                sr.ReadLine();
                for (int i = 0; i < 7; ++i)
                {
                    line = sr.ReadLine();//重采样参数: 

                    line = Regex.Replace(line, @"\s", " ");
                    // Console.WriteLine(line);
                    string[] strs = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    ConfigData h = new ConfigData(strs[0], strs[1], strs[2], strs[3], strs[4], strs[5], strs[6]);
                    list.Add(h);
                }
                this.dataGridView1.DataSource = list;

                
                sr.ReadLine();
                line = sr.ReadLine();//是否做磁场相关(0为不做，1为做)
                if (line.Trim().Equals("0"))
                    this.checkBox4.Checked = false;
                else
                    this.checkBox4.Checked = true;
                /*
                sr.ReadLine();
                line = sr.ReadLine();//
                this.textBox1.Text = line;
                sr.ReadLine();
                line = sr.ReadLine();//
                this.textBox2.Text = line;
                sr.ReadLine();
                line = sr.ReadLine();//
                this.textBox3.Text = line;
                sr.ReadLine();
                line = sr.ReadLine();//
                this.textBox4.Text = line;
                 * */
                sr.Close();
            }
            catch (Exception ex)
            {
                sr.Close();
                MessageBox.Show("配置文件错误");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ConfigForm_Load(object sender, EventArgs e)
        {
            //Console.WriteLine(selectpathconfig + "\\" + "SiteInfo.dat");
            ReadData(selectpathconfig + "\\" + "SiteInfo.dat");
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {

        }
    }
}
